package com.geek.homework.If;

/**
 * @author SunBingJian
 * @desc TODO
 * @date 2025/9/2
 */

/**
 * 1.需求：if示例,从键盘接收两个数字,再接收一个符号,然后进行运算
 * -------请输入第一个数字:8
 * -------请输入第二个数字:9
 * -------请输入运算符号:+
 * -------8+9=17
 */

import java.util.Scanner;

public class If_work01 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        // 接收第一个数字
        System.out.print("请输入第一个数字:");
        double a = scanner.nextDouble();
        
        // 接收第二个数字
        System.out.print("请输入第二个数字:");
        double b = scanner.nextDouble();
        
        // 接收运算符号
        System.out.print("请输入运算符号:");
        char operator = scanner.next().charAt(0);
        
        // 根据运算符进行计算
        if (operator == '+') {
            System.out.println(a + "+" + b + "=" + (a + b));
        } else if (operator == '-') {
            System.out.println(a + "-" + b + "=" + (a - b));
        } else if (operator == '*') {
            System.out.println(a + "*" + b + "=" + (a * b));
        } else if (operator == '/') {
            if (b != 0) {
                System.out.println(a + "/" + b + "=" + (a / b));
            } else {
                System.out.println("除数不能为0！");
            }
        } else {
            System.out.println("运算符不支持！");
        }
        
        scanner.close();
    }
}
